package com.lhy;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

public class Test58 {
    public static void main(String[] args) {
        ArrayList<String> list = new ArrayList<>();
        list.add("你好呀");
        list.add(",");
        list.add("小坏蛋");
        for (String i: list){
            System.out.println(i);
        }
        System.out.println(list.size());
        MyArrayMap(1,"你好1");
        MyArrayMap(2,"你好2");
        MyArrayMap(3,"你好3");
        MyArrayMap(4,"你好4");
        MyArrayMap(5,"你好5");
    }

    public static void MyArrayMap(int i, String s){
        //集合内的类型必须为引用数据类型，其他的类型可用封包，装包在Number类中。
        HashMap<Integer, String> map = new HashMap<>();
        map.put((int)i,s);
        //使用迭代的方式遍历
        Iterator<Map.Entry<Integer, String>> iterator = map.entrySet().iterator();
        if(i == 5) {
            /*while (iterator.hasNext()) {
                Map.Entry<Integer, String> next = iterator.next();
                System.out.println("key: " + next.getKey() + ",andValue: " + next.getValue());
            }*/
            System.out.println("key:"+map.keySet()+"and Value: "+map.get(i));
        }
        System.out.println("key:"+map.keySet()+"and Value: "+map.get(i));
    }
}
